<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>客户管理-客户详情</title>
	<link rel="stylesheet" href="/js/plugin/layui-v2.3.0/layui/css/layui.css">
	<link rel="stylesheet" href="/js/plugin/layui-v2.3.0/layui/css/formSelects-v4.css">
	<link rel="stylesheet" href="/css/reset.css">
	<link rel="stylesheet" href="/css/index.css">
	<link rel="stylesheet" href="/css/project_set.css">
	<link rel="stylesheet" href="/css/client.css">
	<script src='/js/jquery-2.1.1.min.js'></script>
    <script src='/js/plugin/layui-v2.3.0/layui/layui.js'></script>
    <script src='/js/common.js'></script>
</head>
<style>
 ::-webkit-scrollbar-thumb {
   background-color: #a2a2a2;
   border-radius: 2px;
}
::-webkit-scrollbar{width:6px;}
	body{
		overflow-y: scroll;
	} 
.form-content .layui-form-label{
	padding: 9px 0px;
}
.layui-input-block{
	color: #999999;
}
#template .layui-anim.layui-icon{/* 单选按钮大小 */
	font-size: 15px;
}
/* 更新客户状态 让灰色背景保持填满 */
#template,#template>div,form{
	height: 100%;
}
div.flow-communicate{
	min-height: calc(100% - 135px);
	border-width: 0;
}
.layui-input-block span{
	display: inline-block;
	height: 36px;
	line-height: 36px;
}
#temolateRecommend .layui-form-label{/* 选择推荐房间表单 右对齐 */
	text-align: right;
}
</style>
<body style="box-sizing: border-box;">
	<div class="kb-content my-locations-list">
		<section class="kb-content-container clearfix">
			<header class="nav-header">
				 <div class="nav-section-header-title">
				 	<span th:text="${record.customerName}" >小娟</span>
				 	<div class="d-iblock"><span class="font-14 color-nine" >公司名：</span><span class="font-14 color-nine" th:text="${#strings.isEmpty(record.corporateName)?'无':record.corporateName}" >小娟</span></div>
				 	<div class="d-iblock m-left-sm"><span class="font-14 color-nine" >行业：</span><span class="font-14 color-nine" th:text="${#strings.isEmpty(record.dicIndustryStr)?'无':record.dicIndustryStr}" >小娟</span></div>
				 	<div class="d-iblock m-left-sm"><span class="font-14 color-nine" >类型：</span><span class="font-14 color-nine" th:text="${#strings.isEmpty(record.dicCorporateTypeStr)?'无':record.dicCorporateTypeStr}" >小娟</span></div>
				 	<div class="f-right">
				 		<button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="customer-edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>
				 		<button type="button" th:if="${sellRecord.customerState==1}" id="add_team" class="layui-btn layui-btn-normal layui-btn-radius"><i class="layui-icon layui-icon-form"></i>新增团队</button>
				 	</div>
				 </div>
				 <div class="nav-section-action-bar">
				 	 <div class="action-bar-type m-right-sm"><span class="m-none" >联系人：</span><span th:text="${#strings.isEmpty(record.contactsName)?'无':record.contactsName}">偶家科技</span></div>
				 	 <div class="d-iblock color-nine"><i class="layui-icon layui-icon-cellphone"></i><span th:text="${#strings.isEmpty(record.contactsTelephone)?'无':record.contactsTelephone}" >无</span></div>
				 	 <div class="d-iblock m-left-sm color-nine"><i class="layui-icon layui-icon-login-wechat"></i><span th:text="${record.wechat!=null?record.wechat:'无'}" >无</span></div>
				 	 <div class="d-iblock m-left-sm color-nine"><span>邮箱：</span><span th:text="${#strings.isEmpty(record.mailbox)?'无':record.mailbox}" >2018001</span></div>
				 	 <div class="d-iblock m-left-sm color-nine"><span>代理人电话：</span><span th:text="${#strings.isEmpty(record.agentTelephone)?'无':record.agentTelephone}" >2018001</span></div>
				 </div>
			</header>
			<div class="nav-section-content-container pad-top-30 clearfix">
				<div class="nav-content-1 f-left">
					<div class="nav-comment-container kb-form-container crm-opp-info" style="padding:0">
						<div class="opp-status-container mag-bot-20">
							<div class="opp-status mag-bot-20 flex">
								<div class="single-status index-1 " th:classappend="${sellRecord.customerState==0}?'status-active'"><i class="icon-crm_status_1"></i><span>初步接洽</span></div>
								<div class="single-status index-3 " th:classappend="${sellRecord.customerState==1}?'status-active'"><i class="icon-crm_status_3"></i><span>赢单</span></div>
								<div class="single-status index-5" th:classappend="${sellRecord.customerState==2}?'status-active'"><i class="icon-crm_status_5"></i><span>流失</span></div>
							</div>
							<button class="layui-btn layui-btn-normal layui-btn-lg btn-bg" id="update-customer">更新客户状态</button>
						</div>
						<fieldset class="fieldset">
							<legend>参观记录</legend>
							<div class="box-content">
								<div class="t-center">
									<!-- <img alt="" class="net-problem-pic" src="/images/network-problem.jpg">
									<p class="color-nine">还没有信息</p> -->
									<table id="visitRecord" lay-filter="visitRecord" ></table>
								</div>
							</div>
						</fieldset>
						<fieldset class="fieldset">
							<legend>客户意向</legend>
							<div class="form-content">
								<div class="layui-form-item">
									<label for="" class="layui-form-label">入驻意愿</label>
									<div class="layui-input-block" th:switch="${record.admissionDesire}">
										<span th:case="0">很强烈</span>
										<span th:case="1">一般</span>
										<span th:case="*">暂无</span>
									</div>
								</div>
								<div class="layui-form-item">
									<label for="" class="layui-form-label">意向分店</label>
									<div class="layui-input-block  crm-requirement-square">
											<div>
												<span class="title">工位租赁</span>
											</div>
											<div class="layui-form-item">
												<label for="" class="layui-form-label">入驻意愿</label>
												<div class="layui-input-block">
													<span>暂无</span>
												</div>
											</div>
											<div class="layui-form-item">
												<label for="" class="layui-form-label">出租类型</label>
												<div class="layui-input-block">
													<span>暂无</span>
												</div>
											</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label for="" class="layui-form-label">推荐房间</label>
									<div class="layui-input-block  crm-requirement-square">
										<div></div>
									    <div class="layui-form-item">
											<label for="" class="layui-form-label">推荐房间</label>
											<div class="layui-input-block">
												<span><a href="#" class="a-link">A011(能+空间（金泰大厦项目）)</a></span>
											</div>
										</div>
										<div class="layui-form-item">
											<label for="" class="layui-form-label">兴趣程度</label>
											<div class="layui-input-block">
												<span>暂无</span>
											</div>
										</div>
									</div>
								</div>
							</div>
						</fieldset>
					</div>
				</div>
				<div class="nav-content-2 f-right">
					<div class="nav-container-content" style="margin-bottom: 0">
						<header class="kb-title clearfix m-bottom-sm"><h2 class="header-title f-left">待跟进事项</h2></header>
						<div class="nav-body">
							<ul class="nav-container-list-else">
								<li>
									<div class="flex-between">
										<span class="">跟进人</span>
										<a href="javascript:;" class="a-link" th:text="${record.executorStr}" >冯振轩</a>
									</div>
								</li>
								<li>
									<div class="flex-between">
										<span class="">跟进时间</span>
										<a href="javascript:;" class="a-link" th:text="${#dates.format(record.created, 'yyyy-MM-dd')}" >7天前</a>
									</div>
								</li>
							</ul>
						</div>
					</div>	
					<div class="nav-container-content" style="margin-bottom: 0">
						<header class="kb-title clearfix mag-bot-20"><h2 class="header-title f-left">销售记录</h2></header>
						<div style="width: 100%; height: 100%; position: relative;">
							<div class="nav-comment-container" th:each="sell : ${sellRecordLog}">
								<div class="nav-comment-content border-bottom-lg">
									<header class="clearfix">
										<div class="comment-portrait">
											<img src="/images/user_head.jpg" style="width: 36px; height: 36px; border-radius: 100px;">
										</div>
										<div class="comment-name">
											<span class="comment-people" th:text="${sell.fkDicCauseLoss}" >Admin</span><span th:text="${#dates.format(sell.created, 'yyyy-MM-dd')}" class="comment-time">9 天前</span>
										</div>
									</header>
									<div class="nav-comment-text">
										<p style="margin-bottom: 8px; color: rgb(153, 153, 153);"><span style="color: rgb(51, 51, 51);" th:text="${sell.sellInfo}" ></span></p>
										<div class="communicate under-line">
											<span class="status-initial" style="min-width: 64px;text-align: center;" th:if="${sell.customerState==0}">初步接洽</span>
											<span class="status-win" style="min-width: 64px;text-align: center;" th:if="${sell.customerState==1}">赢单</span>
											<span class="status-failed" style="min-width: 64px;text-align: center;" th:if="${sell.customerState==2}">流失</span>
											<i class="layui-icon layui-icon-user"></i>
											<span><a href="javascript:;" th:text="${sell.fkCustomer}" style="color: rgb(153, 153, 153);">
												test2</a>
											</span>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<!-- <div>
						<header class="kb-title clearfix mag-bot-20"><h2 class="header-title f-left">销售记录</h2></header>
						<div class="m-updown">
							<div class="common-search f-left" style="width: 246px;">
							  <input class="layui-input" placeholder="按关键词搜索" type="text">
							</div>
						</div>
					</div>
					<div class="nav-container-content" style="margin-bottom: 0">
						<header class="kb-title clearfix m-bottom-sm"><h2 class="header-title f-left">备注</h2></header>
						<div class="nav-body">
							<p>暂无备注</p>
						</div>
					</div> -->	
				</div>
			</div>		
		</section>
	</div>
</body>
<!-- 客户销售记录模板 -->
<div id="template" style="display: none;" >
	<div>
		<form class="layui-form" lay-filter="detailsForm" >
			<div class="layui-row">							
	  				<div class="layui-form-item">
				    <label class="layui-form-label" style="width:120px;padding-left: 25px;">选择客户状态</label>
				    <div class="layui-input-block" style="margin-left:180px">
				      <input lay-filter="csmState" lay-verify="csmState" name="customerState" title="初步接洽" type="radio" value="0" checked><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i><div>初步接洽</div></div>
				      <input lay-filter="csmState" name="customerState" title="赢单 " type="radio" value="1"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>赢单 </div></div>
				      <input lay-filter="csmState" name="customerState" title="流失   " type="radio" value="2"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>流失   </div></div>
				    </div>
				</div>					    		
			</div>
			<div class="flow-communicate" style="margin-bottom: 0;">
	    		<div class="communicate-arrow" style="display: inline-block; left: 200px;"><em></em><span style="top: 0;" ></span></div><!-- top=0 去掉三角的边框 -->
	   			<div class="layui-form-item">
				    <label class="layui-form-label">销售记录</label>
				    <div class="layui-input-block">
				       <textarea name="sellInfo" placeholder="请填写销售记录" class="layui-textarea" style="height:68px"></textarea>
				    </div>
				</div>
				<div class="layui-form-item">
				    <label class="layui-form-label">沟通方式</label>
				    <div class="layui-input-block">
				      <input type="radio" name="communicateMode" value="0" title="顾客上门" lay-filter="linkType">
				      <input type="radio" name="communicateMode" value="1" title="电话通讯 "  lay-filter="linkType">
				      <input type="radio" name="communicateMode" value="2" title="发送邮件   "  lay-filter="linkType">
				      <input type="radio" name="communicateMode" value="3" title="微信沟通 "  lay-filter="linkType">
				      <input type="radio" name="communicateMode" value="4" title="QQ沟通   "  lay-filter="linkType">
				      <input type="radio" name="communicateMode" value="5" title="其他 "  lay-filter="linkType">
				    </div>
				</div>
				<div class="layui-form-item">
				    <label class="layui-form-label">是否参观</label>
					    <div class="layui-input-block">
				      		<input type="radio" name="visit" value="0" title="客户已参观" lay-filter="visitFleg">
							<div class="visit-choice-container hide mag-bot-20"><!-- 是否参观 -->
								<div class="layui-row">
									<div class="layui-form-item">
										<div class="layui-input-inline" style="width: 240px;">
										<select name="fkProjectid" id="fkProjectid" >
											<option value="">选择分店</option>
										</select>
										</div>
										    <div class="layui-input-inline" style="width: 240px;">
										        <select name="visitUser" id="visitUser" >
										     	 	<option value="">选择代领人</option>
											   </select>
										    </div>
										    <div class="layui-input-inline" style="width: 240px;">
										        <input type="text" name="visitDate" id="visitDate" readonly='readonly' autocomplete="off" class="layui-input date-input" placeholder="选择创建日期">	
										    </div>
										</div>		
		    						</div>
						      		<div class="layui-row">
						      			 <input type="text" name="visitRemarks"  autocomplete="off" class="layui-input layui-input-inline" placeholder="备注" style="width: 720px;">	
						      			 <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="addVisit" >添加</button>
						      		</div>
						      		<!-- 存放客户参观信息 -->
						      		<div class="layui-row visitList"></div>
						      </div>
					     </div>
					     <div class="layui-input-block">
						      <input type="radio" name="visit" value="1" title="客户预约参观 "  lay-filter="visitFleg">
						      <div class="visit-choice-container hide mag-bot-20">
						      		<div class="layui-row">
							      		<div class="layui-form-item">
							      			<div class="layui-input-inline" style="width: 240px;">
												<input type="text" name="subVisitDate" id="subVisitDate" autocomplete="off" class="layui-input date-input" placeholder="选择创建日期">	
											</div>
							      		</div>
						      		</div>
						      </div>
					     </div>
					     <div class="layui-input-block">
					      		<input type="radio" name="visit" value="2" title="客户未参观   "  lay-filter="visitFleg">
					     </div>
				</div>
				<div class="layui-form-item">
				    <label class="layui-form-label">是否推荐</label>
				    <div class="layui-input-block">
						<input type="radio" name="recommend" th:checked="${sellRecord.recommend==1}" value="1" title="已向客户推荐" lay-filter="recommend"> 
						<button type="button" class="layui-btn layui-btn-normal layui-btn-radius f-right" th:classappend="${sellRecord.recommend!=1?'hide':''}" id="add-goodRoom">添加推荐房间</button>
				    </div>
				    <!-- 推荐房间记录列表 -->
				    <div class="layui-input-block roomList">
				    	<div id="roolListTemplate" style="display: none;"><!-- 模板 主要用来给js使用 -->
					    	<div class="roomListItem" style="display: inline-block;" >
					    		<p>
					    			<span class="recName" ></span>
					    			<i data-partition="" class="layui-icon layui-icon-close-fill delRoomList" ></i>
					    		</p>
					    		<p class="recState" ></p>
					    	</div>
				    	</div>
				    	<!-- 循环展示已经保存的 -->
				    	<div class="roomListItem" style="display: inline-block;" th:each="rr:${sellRecord.recommendRecordList}" >
				    		<p>
				    			<span th:text="${rr.partitionName+'('+rr.projectName+')'}"></span>
				    			<i th:attr="data-partition=${rr.fkPartition}" class="layui-icon layui-icon-close-fill delRoomList" ></i>
				    		</p>
				    		<p th:text="'兴趣：'+${rr.admissionDesire==0?'很强烈':'一般'}"></p>
				    	</div>
				    </div>
				    <div class="layui-input-block">
						<input type="radio" name="recommend" value="0" th:checked="${sellRecord.recommend!=1}" title="未向客户推荐 " lay-filter="recommend">
				    </div>
				</div>
	    		<div class="layui-form-item itemChange start-item loss-item">
				    <label class="layui-form-label">可对比竞品</label>
				    <div class="layui-input-block">
				      <input type="text" name="contrastive"  placeholder="" autocomplete="off" class="layui-input">
				    </div>
	    		</div>
	    		<div class="layui-form-item itemChange start-item">
				    <label class="layui-form-label">下次跟进</label>
				    <div class="layui-input-block">
				      <input type="text" name="nextTimDate" id="nextTimDate" readonly='readonly' placeholder="" autocomplete="off" class="layui-input">
				    </div>
	    		</div>
	    		<div class="layui-form-item itemChange win-item hide">
				    <label class="layui-form-label"><span class="must-fill">*</span>赢单分店</label>
				    <div class="layui-input-block">
					      <select name="winProjectid" id="winProjectid" >
				     	 	<option value="">选择赢单的分店</option>
					      </select>
				    </div>
	    		</div>
	    		<div class="layui-form-item itemChange loss-item hide">
				    <label class="layui-form-label"><span class="must-fill">*</span>流失原因</label>
				    <div class="layui-input-block">
					      <select name="fkDicCauseLoss" id="fkDicCauseLoss">
				     	 	<option value="">请选择</option>
					      </select>
				    </div>
	    		</div>
	    		<div class="layui-form-item">
	    			<span class="layui-btn layui-btn-normal btn-bg f-right " lay-submit lay-filter="submitBtn" >发布</span>
	    		</div>
	    	</div>
		</form>
	</div>
</div>
<!-- 推荐房间弹窗模板 -->
<div id="temolateRecommend" style="display: none;" >
	<div style="padding: 30px 0 0 0">
		<div class="layui-form" lay-filter="recommend-form" >
			<div class="layui-form-item" >
				<label class="layui-form-label"><span class="must-fill">*</span>推荐房间</label>
				<div class="layui-input-inline">
					<select name="fkProjectid" lay-verify="required" lay-filter="fkProjectid" id="recProject" >
						<option value="">选择分店</option>
					</select>
				</div>
				<div class="layui-input-inline">
					<select name="fkPartition" lay-verify="required" id="fkPartition" >
						<option value="">选择房间</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">兴趣程度</label>
				<div class="layui-input-block">
					<input type="radio" name="admissionDesire" value="0" title="很强烈">
					<input type="radio" name="admissionDesire" value="1" title="一般" checked="checked" >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<textarea name="remark" class="layui-textarea" style="width: 80%;" ></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" lay-submit class="layui-btn layui-btn-normal layui-btn-radius" id="add-goodRoom-run" lay-filter="add-goodRoom-run" >添加推荐房间</button>
					<button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="add-goodRoom-close" >完成添加</button>
				</div>
			</div>
			<div class="room-list layui-form-item">
				<!-- 房间列表 -->
				<div></div>
			</div>
		</div>
	</div>
</div>
<script th:inline="javascript">
var visitList = new Array(); //用来保存参观信息
var roomList=[[${sellRecord.recommendRecordList}]];//保存推荐房间列表
$(function() {
	layui.config({
		base: '/js/plugin/layui-v2.3.0/layui/' //此处路径请自行处理, 可以使用绝对路径
	}).extend({
		formSelects: 'formSelects-v3'
	}).use(["layer", 'table',"layer", "form", 'formSelects','laydate'],function() {
		var layer = layui.layer,
		table = layui.table,
		form = layui.form,
		laydate = layui.laydate;
		
		//初始化select
		initFormSelects("fkDicCauseLoss", "/system/data-dic/selectjson/dic_customer_loss"); //流失原因
		initFormSelectsExt({ //分店
			id: "fkProjectid,#winProjectid,#recProject",
			url: "/app/customerInfo/getProjectJson",
			first: "请选择分店",
			defaultValue:[[${sellRecord.winProjectid}]]
		});
		initFormSelectsExt({ //带领人
			id: "visitUser",
			url: "/system/org/user/selectjson",
			first: "请选择带领人"
		});
		
		//初始化表单数据
		form.val("detailsForm",{
			customerState:[[${sellRecord.customerState}]]+'',
			sellInfo:[[${sellRecord.sellInfo}]],
			communicateMode:[[${sellRecord.communicateMode}]]+'',
			visit:[[${sellRecord.visit}]]+'',
			contrastive:[[${sellRecord.contrastive}]],
			subVisitDate:function(){//预约参观时间
				return [[${sellRecord.visit==1?#dates.format(sellRecord.visitRecord[0].visitDate, 'yyyy-MM-dd'):null}]];
			},
			nextTimDate:[[${sellRecord.nextTimDate!=null?#dates.format(sellRecord.nextTimDate, 'yyyy-MM-dd'):null}]]
		});
		csmStateF({value:[[${sellRecord.customerState}]]});//客户状态执行一下 定位到具体状态tab
		visitFlegF({value:[[${sellRecord.visit}]]});//是否参观执行一下 定位到具体状态tab
		
		//初始化日期插件
		laydate.render({
			elem: '#nextTimDate', //下次跟进
			btns: ['now', 'confirm']
		});
		laydate.render({
			elem: '#visitDate', //参观时间
			btns: ['now', 'confirm']
		});
		laydate.render({
			elem: '#subVisitDate' //预约参观时间
		});
		
		//选择客户状态
		form.on('radio(csmState)',csmStateF);
		function csmStateF(data) {
			$(".flow-communicate").removeClass("hide");
			$(".flow-communicate .itemChange").addClass("hide");
			if (data.value == 0) {
				$(".flow-communicate .start-item ").removeClass("hide");
				$(".communicate-arrow").css("left", "200px");
			} else if (data.value == 1) {
				$(".flow-communicate .win-item ").removeClass("hide");
				$(".communicate-arrow").css("left", "300px");
			} else {
				$(".flow-communicate .loss-item ").removeClass("hide");
				$(".communicate-arrow").css("left", "380px");
			}
		}
		//是否推荐
		form.on('radio(recommend)',function(data) {
			if (data.value == 1) {
				$("#add-goodRoom").removeClass('hide')
			} else {
				$("#add-goodRoom").addClass('hide')
			}
		});
		//选择是否参观
		form.on('radio(visitFleg)',visitFlegF);
		function visitFlegF(data) {
			var $t=$('.visit-choice-container');
			$t.addClass("hide");
			if (data.value == 1 || data.value == 0) {
				$t.eq(data.value).removeClass("hide");
			}
		}
		//监听更新客户状态提交
		form.on('submit(submitBtn)',function(data){
			data.field.fkCustomer=[[${record.id}]];//赋值客户id
			$.post("/app/customerInfo/updateCustomerStaus",{
				srJson:JSON.stringify(data.field),
				visitList:JSON.stringify(visitList),
				roomList:JSON.stringify(roomList)
			},function(data){
				top.layer.msg(data.error, {
					icon: 1
				});
			},"json");
			return false;
		});
		//监听添加推荐房间提交，这是不是真的提交 而是赋值给变量 和客户状态一起提交
		form.on('submit(add-goodRoom-run)',function(data){
			if(data.field.fkProjectid&&data.field.fkPartition&&checkRoomList(data.field.fkPartition)){//保证这俩数据有值
				var v1Str=$("#recProject").find("option:selected").text();//分店名称
				var v1Val=data.field.fkProjectid;//分店值
				var v2Str=$("#fkPartition").find("option:selected").text();//房间名称
				var v2Val=data.field.fkPartition;//房间值
				var v3=data.field.admissionDesire==0?'很强烈':"一般";//兴趣
				
				//创建模板对象 增加标签
				var $tl=$($("#roolListTemplate").html());
				$tl.find(".recName").text(v1Str+"("+v2Str+")");
				$tl.find(".layui-icon-close-fill").attr("data-partition",v2Val).click(delRoomClick);
				$tl.find(".recState").text("兴趣："+v3);
				$("div.roomList").append($tl);
				
				//加入到数组中				
				roomList.push(data.field);
				layer.msg("已添加");
			}
			return false;
		});
		//监听推荐分店下拉 联动推荐房间
		form.on('select(fkProjectid)',function(data){
			$.getJSON("/app/customerInfo/findPartitionByProject",{projectid:data.value},function(data){
				var partition = $("#fkPartition");
				partition.html('<option value>选择房间</option>');
				$.each(data,function(i,v){
					partition.append('<option value="'+v.id+'">'+v.partitionName+'</option>');
				});
				form.render('select', 'recommend-form');//刷新表单
			});
		});
		function checkRoomList(val){//校验该推荐房间是否可添加 val：分区id
			for(var i=0;i<roomList.length;i++){//循环遍历 看是否可插入
				if(roomList[i].fkPartition==val){
					layer.msg("该房间已经存在");
					return false;
				}
			}
			return true;
		}
		
		//参观记录表格部分
		table.render({
			elem: '#visitRecord',
			url: '/app/customerInfo/listVisitData',
			//数据接口
			page: true,
			//开启分页
			width: 770,
			limit: 10,
			loading: true,
			limits: [10, 30, 60],
			where: {
				params: {
					cid: [[${record.id}]]
				}
			},
			text: {
				none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			},
			cols: [[ //表头
			{
				field: 'fkProjectid',
				title: '参观分店',
				align: 'center',
				width: 100
			},
			{
				field: 'visitDate',
				title: '参观时间',
				align: 'center',
				width: 120
			},
			{
				field: 'visitUser',
				title: '带领人',
				align: 'center',
				width: 80
			},
			{
				field: 'visitRemarks',
				align: 'left',
				width: 430,
				title: '备注'
			}]]
		});
	});
	
	/****绑定自定义事件****/
	
	//添加客户参观信息
	$("#addVisit").click(function() {
		var v1 = $("select[name='fkProjectid']"); //参观分店 option:selected
		var v2 = $("select[name='visitUser']"); //参观带领人
		var v3 = $("input[name='visitDate']"); //参观日期
		var v4 = $("input[name='visitRemarks']"); //参观备注
		var visit = { //添加到集合中  用来提交表单到后台
			fkProjectid: v1.val(),
			visitUser: v2.val(),
			visitDate: v3.val(),
			visitRemarks: v4.val()
		};
		if (pushProject(visit)) { //添加参观展示信息
			layer.msg("已添加");
			$("div.visitList").append("<div class='layui-inline'>" + v1.find("option:selected").text() + "</br>" + v2.find("option:selected").text() + "</div>");
		}
	});
	//更新客户状态
	$("#update-customer").click(function(){
		layer.open({
			type: 1,
			area: ['1100px', '90%'],
			content: $("#template"),
			end:function(){
				location.reload();
			}
		});
	});
	var addRoomIndex;
	$("#add-goodRoom").click(function(){//更新客户状态中的 添加推荐房间
		addRoomIndex=layer.open({
			type: 1,
			offset:"20%",
			area: ['600px', '460px'],
			content: $("#temolateRecommend")
		});
	});
	$("#add-goodRoom-close").click(function(){//添加推荐房间 完成添加 关闭弹窗 
		layer.close(addRoomIndex);
	});
	
	//编辑按钮
	$("#customer-edit").click(function(){
		parent.layer.open({
			type: 2,
			title: "添加新员工",
			area: ['650px', '90%'],
			shade: [0.6, '#010101'],
			content: "/app/customerInfo/edit/"+[[${record.id}]],
			end:function(){
				location.reload();
			}
		});
	});
	
	//插入参观数据 如果不存在这插入返回true否则相反
	function pushProject(visit) {
		if (visit.fkProjectid == "" || visit.visitUser == "") {
			layer.msg('分店和代理人必填', {
				icon: 5
			});
			return false;
		}
		for (var i = 0; i < visitList.length; i++) {
			if (visit.fkProjectid == visitList[i].fkProjectid) { //如果已经存在则插入失败
				layer.msg('分店已存在,请选择其它分店', {
					icon: 5
				});
				return false;
			}
		}
		visitList.push(visit);
		return true;
	}
	//删除已添加的推荐房间
	$("i.delRoomList").click(delRoomClick);
	function delRoomClick(){
		delRoolList($(this).attr("data-partition"));
		$(this).parents("div.roomListItem").remove();
	}
	
	function delRoolList(val){//删除推荐房间 val:分区id
		for(var i=0;i<roomList.length;i++){//循环遍历
			if(roomList[i].fkPartition==val){
				roomList.splice(i, 1);
				return;
			}
		}
	}
	
	$('#add_team').on("click",function(){
		top.layer.open({
			  type: 2, 
			  title:"添加新公司",
			  area: ['750px','90%'],
		      shade: [0.6, '#000'],
		      zIndex:800,
			  content:"/app/customerTeam/add/"+[[${sellRecord.winProjectid}]]+"?cusId="+[[${record.id}]]
		});
	});
	
});
</script>
</html>
